#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int cal_gcd(int a, int b)
{
        if(b == 0){
                return a;
        }
        return cal_gcd(b, a%b);
}

int main()
{
        int n = 0, q = 0;
        cin >> n >> q;
        vector<int> arr(n + 1, 0);
        vector<int> log2(n + 1, 0);
        for(int i = 1; i <= n; i++){
                cin >> arr[i];
        }

        int k = std::log2(n);
        vector<vector<int>> gcd(n + 1, vector<int>(k + 1, 0));
        log2[0] = -1;
        for(int i = 1; i <= n; i++){
                log2[i] = log2[i>>1] + 1;
                gcd[i][0] = arr[i];
        }

        for(int j = 1; j <= k; j++){
                for(int i = 1; i <= n - (1 << j) + 1; i++){
                        gcd[i][j] = cal_gcd(gcd[i][j - 1], gcd[i + (1 << (j - 1))][j - 1]);
                }
        }

        for(int i = 1, l, r; i <= q; i++){
                cin >> l >> r;
                // if(l == r){
                //         cout << arr[l] << endl;
                //         continue;
                // }
                int p = log2[r - l + 1];
                cout << cal_gcd(gcd[l][p], gcd[r - (1 << p) + 1][p]) << endl;
        }

        return 0;
}